package org.linlinjava.litemall.db.service;

 
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.linlinjava.litemall.db.beans.Constants;
import org.linlinjava.litemall.db.dao.LumiereSubscribeUserMapper;
import org.linlinjava.litemall.db.domain.LumiereSubscribeUser;
import org.linlinjava.litemall.db.domain.LumiereSubscribeUserExample;
import org.linlinjava.litemall.db.dto.SubscribeUserOrderDTO;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.awt.print.Pageable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class LumiereSubscribeUserService extends MPJBaseServiceImpl<LumiereSubscribeUserMapper,LumiereSubscribeUser> {
    @Resource
    private LumiereSubscribeUserMapper lumiereSubscribeUserMapper;



    public int add(LumiereSubscribeUser lumiereSubscribe){
        return  lumiereSubscribeUserMapper.insertSelective(lumiereSubscribe);
    }

    public Long querySubscribeUserById(Integer suscribeId){
        LumiereSubscribeUserExample example = new LumiereSubscribeUserExample();
        example.or().andSubscribeIdEqualTo(suscribeId);
        return lumiereSubscribeUserMapper.countByExample(example);
    }

    public int update(LumiereSubscribeUser lumiereSubscribeUser){
        return lumiereSubscribeUserMapper.updateByPrimaryKeySelective(lumiereSubscribeUser);
    }

//    public int updateByExample()

    public void deleteById(Integer id) {
        lumiereSubscribeUserMapper.logicalDeleteByPrimaryKey(id);
    }

    public LumiereSubscribeUser findById(Integer id) {
        return lumiereSubscribeUserMapper.selectByPrimaryKey(id);
    }

    public List<LumiereSubscribeUser> queryAll(){
        Integer[] status = {1,4};
        LumiereSubscribeUserExample example = new LumiereSubscribeUserExample();
        example.or().andStatusIn(Arrays.asList(status));
        return lumiereSubscribeUserMapper.selectByExample(example);
    }

    public List<LumiereSubscribeUser> queryAllUser(){
        Integer[] status = {0};
        LumiereSubscribeUserExample example = new LumiereSubscribeUserExample();
        example.or().andStatusNotIn(Arrays.asList(status));
        return lumiereSubscribeUserMapper.selectByExample(example);
    }

    public List<LumiereSubscribeUser> queryByUserId(Integer userId,Integer page,Integer limit,String sort,String order,List<Integer> status){
        LumiereSubscribeUserExample example = new LumiereSubscribeUserExample();
        if(status != null && status.size() > 0){
            example.createCriteria().andUserIdEqualTo(userId).andStatusIn(status).andDeletedEqualTo(false);
        }else{
            example.createCriteria().andUserIdEqualTo(userId).andDeletedEqualTo(false);
        }

        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }
//        PageHelper.startPage(page, limit);
        return lumiereSubscribeUserMapper.selectByExample(example);
    }

    public List<LumiereSubscribeUser> queryByUserIdAndSubscribeId(Integer userId,Integer subscribeId){
        LumiereSubscribeUserExample example = new LumiereSubscribeUserExample();
        example.createCriteria().andUserIdEqualTo(userId).andDeletedEqualTo(false).andSubscribeIdEqualTo(subscribeId);
        return lumiereSubscribeUserMapper.selectByExample(example);

    }

    public long querySubscribeId(Integer subscribeId){
        Integer[] status = {0};
        LumiereSubscribeUserExample example = new LumiereSubscribeUserExample();
        example.createCriteria().andDeletedEqualTo(false).andSubscribeIdEqualTo(subscribeId).andStatusNotIn(Arrays.asList(status));
        return lumiereSubscribeUserMapper.countByExample(example);
    }

    public LumiereSubscribeUser queryByLinkId(Integer linkId){
        LumiereSubscribeUserExample example = new LumiereSubscribeUserExample();
        example.createCriteria().andDeletedEqualTo(false).andLinkIdEqualTo(linkId);
        return lumiereSubscribeUserMapper.selectOneByExample(example);
    }

    public List<SubscribeUserOrderDTO> myOrderList(Integer page, Integer limit, Integer userId) {
        //PageHelper.startPage(page, limit);
        return lumiereSubscribeUserMapper.myOrderList(page,limit,userId);
    }
}
